//
//  WCRecordDesCell.m
//  WC
//
//  Created by wsj2015 on 16/1/25.
//  Copyright © 2016年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCRecordDesCell.h"

@implementation WCRecordDesCell

- (void)awakeFromNib {
    // Initialization code
//    [self.titleTf addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
//    [self.bgview setBorderColor:kBorderColor];
//    [self.bgview setCornerRadius:5];
//    [self.contentView setBorderColor:kBorderColor];
//    [self.contentView setCornerRadius:5];
    
    self.bgview.layer.borderColor =kBorderColor.CGColor;
    self.bgview.layer.borderWidth =1;
    self.contentTxtView.layer.borderColor =kBorderColor.CGColor;
    self.contentTxtView.layer.borderWidth =1;
    self.contentTxtView.layer.cornerRadius =5;
    self.contentTxtView.layer.masksToBounds = YES;
    self.contentTxtView.backgroundColor = kAppBg;
    self.contentTxtView.delegate =self;
    self.titleTf.delegate = self;
    [self.contentView setBackgroundColor:kAppBg];

    // Configure the view for the selected state
}

//控制输入字符数
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    //回车键 结束
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }if (range.location>=100)
    {
        //控制输入文本的长度
        return  NO;
    }
    if ([text isEqualToString:@"\n"]) {
        //禁止输入换行
        return NO;
    }
    else
    {
        if (self.contentChanged) {
            self.contentChanged(textView.text);
        }
        return YES;
    }

}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{

    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.titleTf resignFirstResponder];
    return YES;

}

- (void)setEditAable:(BOOL)editAable{
    _editAable = editAable;
    
    self.titleTf.enabled = editAable;
    self.contentTxtView.editable = editAable;
  
    

}
//- (void)textFieldDidChange:(UITextField *)textField
//{
//    if (textField == self.titleTf) {
//        if (textField.text.length > 10) {
//            textField.text = [textField.text substringToIndex:10];
//        }
//    }
//}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
    if (toBeString.length > 11) {
        
        textField.text = [toBeString substringToIndex:11];
        
        return NO;
        
    }
    
    return YES;
    
}
@end

